/*---------------------------------------------------
-----------------------------------------------------
Filename:	fileinfo.m
Version:	3.2
Type:		maki
Date:		10. Aug. 2007 - 20:42 
Author:		Martin Poehlmann aka Deimos
E-Mail:		martin@skinconsortium.com
Internet:	www.skinconsortium.com
		www.martin.deimos.de.vu
-----------------------------------------------------
---------------------------------------------------*/

#include <lib/std.mi>
#include attribs/init_windowpage.m

// #define DEBUG
#define FILE_NAME "fileinfo.m"
#include lib/debug.m

#define WEBCOVER_SHOUTCAST "winamp.cover.shoutcast"
#define WEBCOVER_AOLRADIO "winamp.cover.aolradio"

Function loadFileInfo();
Class GuiObject LinkObject;
Class GuiObject CycleObject;
Function refreshDisplay(int rating);
Class Button RatingButton;
Function showBranding();
Class Group Infoline;
Function Boolean cycle_shiftBack(group item, boolean hide);

Global Group scriptGroup, g_cover;
Global GuiObject l_albumart;
Global InfoLine g_rating, g_title, g_album, g_artist, g_year, g_genre, g_track, g_publisher, g_sname, g_surl;
Global InfoLine g_target;
Global Text t_title, t_album, t_artist, t_year, t_genre, t_track, t_publisher, t_sname, t_surl;
Global Timer cycler;
Global String stationLink;

Global List cycle;
Global Boolean cycler_paused, quick_change;
Global List ratingStars;

#define CENTER_VAR Branding
Global layer l_branding, l_webcover;
#include <lib/centerlayer.m>
#undef CENTER_VAR

Global LinkObject linkArtist, linkAlbum, linkTitle, linkGenre, linkPublisher, linkSURl, linkSname;
Global CycleObject cycleGenre, cyclePublisher, cycleTrack, cycleYear;

Global RatingButton rate1, rate2, rate3, rate4, rate5, rate0;
Global Layer star1, star2, star3, star4, star5;

System.onScriptLoaded()
{
	initAttribs_windowpage();

	scriptGroup = getScriptGroup();

	cycler = new Timer;
	cycler.setDelay(4000);

	g_rating = scriptGroup.findObject("infodisplay.line.rating");
	g_title = scriptGroup.findObject("infodisplay.line.title");
	g_album = scriptGroup.findObject("infodisplay.line.album");
	g_artist = scriptGroup.findObject("infodisplay.line.artist");
	g_year = scriptGroup.findObject("infodisplay.line.year");
	g_genre = scriptGroup.findObject("infodisplay.line.genre");
	g_track = scriptGroup.findObject("infodisplay.line.track");
	g_publisher = scriptGroup.findObject("infodisplay.line.publisher");
	g_sname = scriptGroup.findObject("infodisplay.line.sname");
	g_surl = scriptGroup.findObject("infodisplay.line.surl");

	t_title = g_title.findObject("text.title");
	t_album = g_album.findObject("text.album");
	t_artist = g_artist.findObject("text.artist");
	t_year = g_year.findObject("text.year");
	t_genre = g_genre.findObject("text.genre");
	t_track = g_track.findObject("text.track");
	t_Publisher = g_publisher.findObject("text.publisher");
	t_sname = g_sname.findObject("text.sname");
	t_surl = g_surl.findObject("text.surl");

	linkArtist = g_artist.findObject("link.artist");
	linkAlbum = g_album.findObject("link.album");
	linkTitle = g_title.findObject("link.title");
	linksUrl = g_title.findObject("link.surl");
	linkSname = g_title.findObject("link.sname");
	cycleGenre = g_genre.findObject("link.genre");
	cyclePublisher = g_publisher.findObject("link.publisher");
	cycleTrack = g_track.findObject("link.track");
	cycleYear = g_year.findObject("link.year");
 
	cycle = new List;
	ratingStars = new List;

	group parent = scriptGroup.getParent();
	l_branding = parent.findObject("branding");
	g_cover = parent.findObject("info.component.cover");
	_BrandingInit(l_branding, parent, 1, 0);

	l_albumart = g_cover.getObjecT("winamp.albumart");
	l_webcover = g_cover.getObjecT("winamp.webalbumart");

	rate1 = g_rating.findObject("rate.1");
	rate2 = g_rating.findObject("rate.2");
	rate3 = g_rating.findObject("rate.3");
	rate4 = g_rating.findObject("rate.4");
	rate5 = g_rating.findObject("rate.5");
	rate0 = g_rating.findObject("rate.0");
	ratingStars.addItem(rate1);
	ratingStars.addItem(rate2);
	ratingStars.addItem(rate3);
	ratingStars.addItem(rate4);
	ratingStars.addItem(rate5);

	star1 = g_rating.findObject("star.1");
	star2 = g_rating.findObject("star.2");
	star3 = g_rating.findObject("star.3");
	star4 = g_rating.findObject("star.4");
	star5 = g_rating.findObject("star.5");

	refreshDisplay(System.getCurrentTrackRating());
	loadFileInfo();
	if (ic_fileinfo.getData() == "1")
	{
		if (getStatus() == STATUS_STOPPED) showBranding();
	}
}

System.onScriptUnloading ()
{
	cycler.stop();
	delete cycler;
}

System.onTitleChange (String newtitle)
{
	//if (last_autotitle == newtitle) return;
	if (StrLeft(newtitle, 1) == "[") {
		if (	StrLeft(newtitle, 7) == "[Buffer"
			||
			//StrLeft(newtitle, 4) == "[Connecting"
			//||
			StrLeft(newtitle, 4) == "[ICY") return;
	}
	//last_autotitle = newtitle;
	debugString(DEBUG_PREFIX "System.onTitleChange() -> loadFileInfo();", D_WTF);
	refreshDisplay(System.getCurrentTrackRating());
	loadFileInfo();
}

loadFileInfo ()
{
	// kill a wrong onTitleChange()
	string s = getPlayItemMetaDataString("streamname");
	//if (strlower(strleft(getPlayItemString(), 4)) == "uvox" && s == "") return;
	debugString(DEBUG_PREFIX "loadFileInfo() {", D_WTF);
	debugString(DEBUG_PREFIX "  System.getPlayItemString(): " + System.getPlayItemString(), D_WTF);
	debugString(DEBUG_PREFIX "  System.getPlayItemDisplayTitle(): " + System.getPlayItemDisplayTitle(), D_WTF);
	if (g_target) g_target.cancelTarget();
	if (g_target) g_target.setAlpha(255);
	g_target = NULL;
	g_rating.hide();
	g_title.hide();
	g_album.hide();
	g_artist.hide();
	g_year.hide();
	g_genre.hide();
	l_branding.hide();
	g_track.hide();
	g_publisher.hide();
	g_cover.setAlpha(255);
	g_surl.hide();
	g_sname.hide();
	cycleTrack.hide();
	cycleGenre.hide();
	cyclePublisher.hide();
	cycleYear.hide();
	cycler.stop();
	cycler_paused = 0;
	stationLink = "";

	Boolean _cycle = (infocomp_cycle.getData() == "1");
	Boolean _rating = (infocomp_show_rating.getData() == "1");

	cycle.removeAll();

	int pos = 1;
	int n = 0; 
	
	debugString(DEBUG_PREFIX "  System.getPlayItemMetaDataString(streamname): " + s, D_WTF);
	if (s != "" || strlower(strleft(getPlayItemString(), 4)) == "uvox")
	{
		debugString(DEBUG_PREFIX "  -> A stream is detected!", D_WTF);
 
		if (strlower(strleft(getPlayItemString(), 4)) == "uvox") { //AOL Radio always starts with uvox://
			debugString(DEBUG_PREFIX "  -> AOL Radio (uvox://)", D_WTF);
			l_albumart.hide();
			l_webcover.setXMLParam("image", WEBCOVER_AOLRADIO);
			l_webcover.show();
		}
		else
		{
			debugString(DEBUG_PREFIX "  -> SHOUTcast !(uvox://)", D_WTF);
			l_albumart.hide();
			l_webcover.setXMLParam("image", WEBCOVER_SHOUTCAST);
			l_webcover.show();
		}

		//s = "AOL Radio - Metal";
		string ss = s;

		string sa = getPlayItemMetaDataString("uvox/artist");
		//sa = "SonaTa ArczticA";
		debugString(DEBUG_PREFIX "  System.getPlayItemMetaDataString(streamtrackartist): " + sa, D_WTF);
		

		s = getPlayItemMetaDataString("uvox/title");
		//s = "The Harvest";
		debugString(DEBUG_PREFIX "  System.getPlayItemMetaDataString(streamtracktitle): " + s, D_WTF);
		if (s != "")
		{
			// Title
			if (n > 0) pos += 15;
			t_title.setText(s);
			g_title.setXmlParam("y", integerToString(pos));
			g_title.show();
			linkArtist.setXmlParam("w", integerToString(t_title.getTextWidth() + t_title.getGuiX()));
			n++;
			cycle.addItem(g_title);

			// Artist 
			if (sa != "")
			{
				if (n > 0) pos += 15;
				t_artist.setText(sa);
				g_artist.setXmlParam("y", integerToString(pos));
				g_artist.show();
				linkArtist.setXmlParam("w", integerToString(t_artist.getTextWidth() + t_artist.getGuiX()));
				n++;
				cycle.addItem(g_artist);				
			}
		}
		else
		{
			s = getPlayItemMetaDataString("streamtitle");
			//s = "Sonata Arctica - Full moon"; 
			debugString(DEBUG_PREFIX "  System.getPlayItemMetaDataString(streamtitle): " + s, D_WTF);
			if (s != "")
			{
				int v = strsearch(s, " - ");
				if (v > 0) {
					string s1 = strleft (s, v);
					string s2 = strright (s, strlen(s) - 3 - v);
	 
					// Title
					if (n > 0) pos += 15;
					t_title.setText(s2);
					g_title.setXmlParam("y", integerToString(pos));
					g_title.show();
					linkArtist.setXmlParam("w", integerToString(t_title.getTextWidth() + t_title.getGuiX()));
					n++;
					cycle.addItem(g_title);
		  
					// Artist 
					if (n > 0) pos += 15;
					if (sa == "") t_artist.setText(s1);
					else t_artist.setText(sa);
					g_artist.setXmlParam("y", integerToString(pos));
					g_artist.show();
					linkArtist.setXmlParam("w", integerToString(t_artist.getTextWidth() + t_artist.getGuiX()));
					n++;
					cycle.addItem(g_artist);
					
				}
				else
				{
					// Title
					if (n > 0) pos += 15;
					t_title.setText(s);
					g_title.setXmlParam("y", integerToString(pos));
					g_title.show();
					linkArtist.setXmlParam("w", integerToString(t_title.getTextWidth() + t_title.getGuiX()));
					n++;
					cycle.addItem(g_title);

					// Artist 
					if (sa != "") {
						if (n > 0) pos += 15;
						t_artist.setText(sa);
						g_artist.setXmlParam("y", integerToString(pos));
						g_artist.show();
						linkArtist.setXmlParam("w", integerToString(t_artist.getTextWidth() + t_artist.getGuiX()));
						n++;
						cycle.addItem(g_artist);				
					}
				}
			}
		}
		// Stream Album
		s = getPlayItemMetaDataString("uvox/album");
		//s = "Ecliptica";
		debugString(DEBUG_PREFIX "  System.getPlayItemMetaDataString(streamtrackalbum): " + s, D_WTF);
		if (s != "")
		{
			if (n > 0) pos += 15;
			t_album.setText(s);
			g_album.setXmlParam("y", integerToString(pos));
			g_album.show();
			linkAlbum.setXmlParam("w", integerToString(t_album.getTextWidth() + t_album.getGuiX()));
			n++;
			cycle.addItem(g_album);
		}

		// Genre
		s = getPlayItemMetaDataString("streamgenre");
		//s = "Symphonic Metal";
		debugString(DEBUG_PREFIX "  System.getPlayItemMetaDataString(streamgenre): " + s, D_WTF);
		if (s != "")
		{
			t_genre.setText(s);
			cycleGenre.setXmlParam("w", "0");
			cycle.addItem(g_genre);
			if (n > 0) pos += 15;
			g_genre.setXmlParam("y", integerToString(pos));
			g_genre.show();
			n++;
		}

		// Set Stream Name
		if (ss != "")
		{
			if (n > 0) pos += 15;
			t_sname.setText(ss);
			g_sname.setXmlParam("y", integerToString(pos));
			g_sname.show();
			linkSname.setXmlParam("w", integerToString(t_sname.getTextWidth() + t_sname.getGuiX()));
			n++;
			cycle.addItem(g_sname);		
		}

		// Stream URL (only visible if we have less than 4 lines till now)
		stationLink = getPlayItemMetaDataString("streamurl");
		//stationLink = "http://radio.shoutcast.com";
		debugString(DEBUG_PREFIX "  System.getPlayItemMetaDataString(streamurl): " + stationLink, D_WTF);
		if (stationLink != "")
		{
			if (n > 0) pos += 15;
			t_surl.setText(stationLink);
			g_surl.setXmlParam("y", integerToString(pos));
			g_surl.show();
			linkSurl.setXmlParam("w", integerToString(t_surl.getTextWidth() + t_surl.getGuiX()));
			n++;
			cycle.addItem(g_surl);
		}

		// setCover

		s = getPlayItemMetaDataString("uvox/albumart");
		if (s != "")
		{
			System.setClipboardText("http://broadband-albumart.music.aol.com/scan/" + s);
			l_webcover.setXmlParam("image", "http://broadband-albumart.music.aol.com/scan/" + s);
			if (l_webcover.isInvalid()) l_webcover.setXMLParam("image", WEBCOVER_AOLRADIO);
		}
	}
	else
	{
		debugString(DEBUG_PREFIX "  -> No stream is detected! we do the normal procedure", D_WTF);
		l_albumart.show();
		l_webcover.hide();

		string s = getPlayItemMetaDataString("title");
		if (s != "")
		{
			t_title.setText(s);
			g_title.setXmlParam("y", integerToString(pos));
			g_title.show();
			linkTitle.setXmlParam("w", integerToString(t_title.getTextWidth() + t_title.getGuiX()));
			n++;
			cycle.addItem(g_title);
		}

		s = getPlayItemMetaDataString("artist");
		if (s != "")
		{
			if (n > 0) pos += 15;
			t_artist.setText(s);
			g_artist.setXmlParam("y", integerToString(pos));
			g_artist.show();
			linkArtist.setXmlParam("w", integerToString(t_artist.getTextWidth() + t_artist.getGuiX()));
			n++;
			cycle.addItem(g_artist);
		}

		s = getPlayItemMetaDataString("album");
		if (s != "")
		{
			if (n > 0) pos += 15;
			t_album.setText(s);
			g_album.setXmlParam("y", integerToString(pos));
			g_album.show();
			linkAlbum.setXmlParam("w", integerToString(t_album.getTextWidth() + t_album.getGuiX()));
			n++;
			cycle.addItem(g_album);
		}

		if (infocomp_show_track.getData() == "1")
		{
			s = getPlayitemMetaDataString("track");
			if (s != "" && s != "-1")
			{
				if (n > 0) pos += 15;
				t_track.setText(s);
				g_track.setXmlParam("y", integerToString(pos));
				g_track.show();
				n++;
				cycleTrack.setXmlParam("w", integerToString(t_track.getTextWidth() + t_track.getGuiX()));
				cycle.addItem(g_track);
			}
		}

		if (infocomp_show_year.getData() == "1")
		{
			s = getPlayItemMetaDataString("year");
			if (s != "")
			{
				t_year.setText(s);
				cycleYear.setXmlParam("w", integerToString(t_year.getTextWidth() + t_year.getGuiX()));
				cycle.addItem(g_year);
				if ((!_rating && n < 5) || (_rating && n < 4))
				{
					if (n > 0) pos += 15;
					g_year.setXmlParam("y", integerToString(pos));
					g_year.show();
					n++;
				}
				else
				{
					if (g_Track.getGuiY() == pos) cycleTrack.show();
					cycleYear.show();
					g_year.setXmlParam("y", integerToString(pos));
					if (_cycle) cycler.start();
					else if (getPrivateString (getSkinName(), "FileInfo_usersel", "") == "year")
					{
						int b = 0;
						if (g_Track.getGuiY() == pos) cycle_shiftBack(g_Track, 1);
						if (b > 0) return;
						g_year.show();
					}
				}
			}
		}

		if (infocomp_show_genre.getData() == "1")
		{
			s = getPlayItemMetaDataString("genre");
			if (s != "")
			{
				t_genre.setText(s);
				cycleGenre.setXmlParam("w", integerToString(t_genre.getTextWidth() + t_genre.getGuiX()));
				cycle.addItem(g_genre);
				if ((!_rating && n < 5) || (_rating && n < 4))
				{
					if (n > 0) pos += 15;
					g_genre.setXmlParam("y", integerToString(pos));
					g_genre.show();
					n++;
				}
				else
				{
					if (g_Track.getGuiY() == pos) cycleTrack.show();
					if (g_year.getGuiY() == pos) cycleYear.show();
					cycleGenre.show();
					g_genre.setXmlParam("y", integerToString(pos));
					if (_cycle) cycler.start();
					else if (getPrivateString (getSkinName(), "FileInfo_usersel", "") == "genre")
					{
						int b = 0;
						if (g_Track.getGuiY() == pos) cycle_shiftBack(g_Track, 1);
						if (g_year.getGuiY() == pos && b == 0) cycle_shiftBack(g_year, 1);
						if (b > 0) return;
						g_genre.show();
					}
				}
			}
		}

		if (infocomp_show_publisher.getData() == "1")
		{
			s = getPlayItemMetaDataString("publisher");
			if (s != "")
			{
				t_publisher.setText(s);
				cyclePublisher.setXmlParam("w", integerToString(t_publisher.getTextWidth() + t_publisher.getGuiX()));
				cycle.addItem(g_publisher);
				if ((!_rating && n < 5) || (_rating && n < 4))
				{
					if (n > 0) pos += 15;
					g_publisher.setXmlParam("y", integerToString(pos));
					g_publisher.show();
					n++;
				}
				else
				{
					if (g_Track.getGuiY() == pos) cycleTrack.show();
					if (g_year.getGuiY() == pos) cycleYear.show();
					if (g_genre.getGuiY() == pos) cycleGenre.show();
					cyclePublisher.show();
					g_publisher.setXmlParam("y", integerToString(pos));
					if (_cycle) cycler.start();
					else if (getPrivateString (getSkinName(), "FileInfo_usersel", "") == "publisher")
					{
						int b = 0;
						if (g_Track.getGuiY() == pos) b += cycle_shiftBack(g_Track, 1);
						if (g_year.getGuiY() == pos && b == 0) b += cycle_shiftBack(g_year, 1);
						if (g_genre.getGuiY() == pos && b == 0) b += cycle_shiftBack(g_genre, 1);
						if (b > 0) return;
						g_publisher.show();	
					}
				}
			}
		}

		if (_rating && n > 1)
		{
			if (n > 0) pos += 15;
			g_rating.setXmlParam("y", integerToString(pos));
			g_rating.show();	
		}
	}

	if (n=0)
	{
		showBranding();
	}
	debugString(DEBUG_PREFIX "}", D_WTF);
}

cycler.onTimer ()
{
	if (l_branding.isvisible()) cycler.stop();
	if (infocomp_cycle.getData() == "0" && !quick_change) { cycler.stop(); return; }
	if (!g_target)
	{
		if (infocomp_show_rating.getData() == "1")
		{
			g_target = cycle.enumItem(3);
			cycle.removeItem(3);
		}
		else
		{
			g_target = cycle.enumItem(4);
			cycle.removeItem(4);
		}
		cycle.addItem(g_target);
	}
	else g_target = cycle.enumItem(cycle.getNumItems()-1);

	g_target.setTargetA(0);
	g_target.setTargetY(g_target.getGuiY());
	if (!quick_change) g_target.setTargetSpeed(0.25);
	else g_target.setTargetSpeed(0);
	g_target.gotoTarget();
}

Boolean cycle_shiftBack(group item, boolean hide)
{
	int max = cycle.getNumItems();
	group g; int v;
	for ( int i = 2; i < max; i++ )
	{
		v = i;
		g = cycle.enumItem(i);
		if (g == item) i = max;
	}
	if (!g) return 1;
	cycle.removeItem(v);
	cycle.addItem(g);
	if (hide) g.hide();
	return 0;
}

g_target.onTargetReached ()
{
	if (g_target.getAlpha() == 0)
	{
		g_target.hide();
		g_target.setAlpha(255);
		if (infocomp_show_rating.getData() == "1")
		{
			g_target = cycle.enumItem(3);
			cycle.removeItem(3);
		}
		else
		{
			g_target = cycle.enumItem(4);
			cycle.removeItem(4);
		}
		g_target.setAlpha(0);
		g_target.show();
		g_target.setTargetA(255);
		g_target.setTargetY(getGuiY());
		if (!quick_change) g_target.setTargetSpeed(0.25);
		else 
		{
			g_target.setTargetSpeed(0);
			if (g_publisher.isVisible()) setPrivateString (getSkinName(), "FileInfo_usersel", getToken(g_target.getID(), ".", 2));
		}
		g_target.gotoTarget();
		cycle.addItem(g_target);
		if (infocomp_cycle.getData() == "1") cycler.start();
		quick_change = 0;
	}
}


infocomp_cycle.onDataChanged ()
{
	if (l_branding.isVisible()) return;
	if (getData() == "1")
	{
		if (cycler_paused) cycler.start();
		else loadFileInfo();
		cycler_paused = 0;
	}
	else
	{
		if (cycler.isRunning()) cycler_paused = 1;
		cycler.stop();
		if (g_track.isVisible()) setPrivateString (getSkinName(), "FileInfo_usersel", "track");
		if (g_year.isVisible()) setPrivateString (getSkinName(), "FileInfo_usersel", "year");
		if (g_genre.isVisible()) setPrivateString (getSkinName(), "FileInfo_usersel", "genre");
		if (g_publisher.isVisible()) setPrivateString (getSkinName(), "FileInfo_usersel", "publisher");
	}
}

InfoLineAttribute.onDataChanged ()
{
	if (l_branding.isVisible()) return;
	loadFileInfo ();
}


/** Cycle Object */

CycleObject.onEnterArea ()
{
	CycleObject.getParent().findObject("label").setAlpha(255);
}

CycleObject.onLeaveArea ()
{
	CycleObject.getParent().findObject("label").setAlpha(180);
}


CycleObject.onLeftButtonDown (int x, int y)
{
	CycleObject.getParent().findObject("label").setAlpha(220);
}

CycleObject.onLeftButtonUp (int x, int y)
{
	if (getAlpha() < 255) return; 

	setAlpha(255);

	if (quick_change) return;
	quick_change = 1;

	cycler.onTimer ();
}

/** Link Objects */

LinkObject.onEnterArea ()
{
	LinkObject.getParent().findObject("label").setAlpha(255);
}

LinkObject.onLeaveArea ()
{
	LinkObject.getParent().findObject("label").setAlpha(180);
}


LinkObject.onLeftButtonDown (int x, int y)
{
	LinkObject.getParent().findObject("label").setAlpha(220);
}

LinkObject.onLeftButtonUp (int x, int y)
{
	if (getAlpha() < 255) return; 

	setAlpha(255);

	string s;
	if (LinkObject == linkArtist) s = t_artist.getText();
	if (LinkObject == linkAlbum) s = t_artist.getText() + " " + t_album.getText();
	if (LinkObject == linkTitle) s = t_artist.getText() + " " + t_title.getText();
	if (stationLink != "" && ( LinkObject == linkSname || LinkObject == linkSurl))
	{
		group sui = scriptGroup.getParentLayout().findObject("sui.content");
		sui.sendAction ("browser_navigate", stationLink, 0, 0, 0, 0);

		return;
	}

	if (s == "") return;

	group sui = scriptGroup.getParentLayout().findObject("sui.content");
	sui.sendAction ("browser_search", s, 0, 0, 0, 0);
}

System.onCurrentTrackRated (int rating)
{
	refreshDisplay(rating);
}

RatingButton.onLeftButtonDown (int x, int y)
{
	RatingButton.setAlpha(255);
}


RatingButton.onleftClick ()
{
	int rating = stringToInteger(getToken(getId(), ".", 1));
	refreshDisplay(rating);
	setCurrentTrackRating(rating);
	for ( int i = 1; i <= rating; i++ )
	{
		guiobject o = ratingStars.enumItem(i-1);
		o.setAlpha(255);
	}
}

RatingButton.onEnterArea ()
{
	int pos = stringToInteger(getToken(getId(), ".", 1));
	int rating = System.getCurrentTrackRating();

	star1.hide();
	star2.hide();
	star3.hide();
	star4.hide();
	star5.hide();

	if (pos >= 1) star1.show();
	if (pos >= 2) star2.show();
	if (pos >= 3) star3.show();
	if (pos >= 4) star4.show();
	if (pos >= 5) star5.show();

	if (pos > rating)
	{
		for ( int i = 1; i <= 5; i++ )
		{
			guiobject o = ratingStars.enumItem(i-1);
			if ( i > pos || i <= rating)
			{
				o.setAlpha(255);
			}
			else
			{
				o.setAlpha(0);
			}
		}
	}
	else
	{
		rate1.setAlpha(255);
		rate2.setAlpha(255);
		rate3.setAlpha(255);
		rate4.setAlpha(255);
		rate5.setAlpha(255);
	}
}

RatingButton.onLeaveArea ()
{
	star1.hide();
	star2.hide();
	star3.hide();
	star4.hide();
	star5.hide();
	rate1.setAlpha(255);
	rate2.setAlpha(255);
	rate3.setAlpha(255);
	rate4.setAlpha(255);
	rate5.setAlpha(255);
}

refreshDisplay (int rating)
{
	rate1.setActivated(rating >= 1);
	rate2.setActivated(rating >= 2);
	rate3.setActivated(rating >= 3);
	rate4.setActivated(rating >= 4);
	rate5.setActivated(rating >= 5);
}

showBranding()
{
	cycler.stop();
	g_cover.setAlpha(0);
	g_rating.hide();
	g_title.hide();
	g_album.hide();
	g_artist.hide();
	g_year.hide();
	g_genre.hide();
	g_track.hide();
	g_publisher.hide();
	g_surl.hide();
	g_sname.hide();

	if (ic_vis_fileinfo.getData() == "1")
	{
		_BrandingsetXSpace(g_cover.getGuiW() / 2);
	}
	else
	{
		_BrandingsetXSpace(0);
	}
	_BrandinghandleResize();
	l_branding.show();
}

System.onPlay ()
{
	refreshDisplay(System.getCurrentTrackRating());
	loadFileInfo();
}

ic_fileinfo.onDataChanged ()
{
	if (getData() == "0")
	{
		cycler.stop();
		l_branding.hide();
	}
	else if (l_branding.isVisible())
	{
		showBranding();		
	}
	else
	{
		loadFileInfo();
	}

}

ic_cover_fileinfo.onDataChanged ()
{
	if (l_branding.isVisible())
	{
		showBranding();		
	}
}

ic_vis_fileinfo.onDataChanged ()
{
	if (l_branding.isVisible())
	{
		showBranding();		
	}
}
